0

I read many posts but i couldn't find an answer to my question. I have a button on a webpage which is linked to a controller. This controller prepares some data and calls the view. In the view I have a php variable with this data.

I want to open a new page/tab and add the content of my php variable. The content of the variable is a SVG string which is readable by all browsers.

I know this is not possible in php. I need to use JavaScript, but how can i add the content of a php variable to a new tab???

Note: I have the string only in the php variable not in a file and I don't want to click again on a link to open a new tab.

Any ideas or solutions?

According to the first answer an example (doesnt work:()

<html>
<head>
    <title>
        Test file
    </title>
    <script>
        var myWindow = window.open('','_newtab');
        myWindow.document.write($('myString').text());

    </script>
</head>
<body>
    <p style="display:none" id="myString">Das kommt auch auf die neue seite</p>
</body>

Chris
  • 159
  • 3
  • 14

1 Answers1

3

PHP is not capable of doing that. You need Javascript. Or you define your button with target blank.

Window open() Method http://www.w3schools.com/jsref/met_win_open.asp

HTML target Attribute http://www.w3schools.com/tags/att_a_target.asp

JS example:

$(document).ready(function(){
    myWindow=window.open('', '_blank')
    myWindow.document.write($('#myString').text());
});

This will open a new window and write #myString content to it. You need to define #myString with your string or whatever you want to display. E.g.

<p id="myString">New window</p>

Here you go http://jsfiddle.net/qBjVG/13/

DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601
  • it would be useless to add target blank to the button because he call a controller and not the next view... and there is no destination file wich i can open with window.open() from javascript because i have only the variable in php – Chris Oct 01 '12 at 10:41
  • Use javascript to open the new window on document load! – DarkLeafyGreen Oct 01 '12 at 10:46
  • That looks like it was very close but it does not...:( – Chris Oct 01 '12 at 11:17
  • In the example at your link is a file called test.html i don't have a file and i don't want to create a file for that...yet ever many thanks for your effort – Chris Oct 01 '12 at 11:23
  • try the code which i have written in according to your answer and see by yourself...anyway many thanks for your effort – Chris Oct 01 '12 at 12:47
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/17395/discussion-between-artworkad-and-chris) – DarkLeafyGreen Oct 01 '12 at 12:53
  • sry i had no more time yesterday...i fixed this problem with a litl work around i wrote my output to a file and opend it with window.open('tempFile') – Chris Oct 02 '12 at 08:41