Reputation: 169
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>
Upvotes: 0
Views: 3817
Reputation: 70406
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/
Upvotes: 3