PDA

View Full Version : Help me with pop up



wais
02-19-2008, 08:31 AM
I need help with document write:
I have this script :


<script type="text/javascript">
<!--
function dirtypop()
{
var generator=window.open('','name','height=500,width= 500,status=1,resizable=0');

generator.document.write('<html><head><title>Popup </title>');
generator.document.write('</head><body>');
generator.document.write('<h1></h1>');
generator.document.write('<p></p>');
generator.document.write('<p><a href="java script:alert(self.location.href)">View the URL of this window</a>.</p>');
generator.document.write('<p><a href="java script:self.close()">Close</a> the popup.</p>');
generator.document.write('</body></html>');
generator.document.close();
}
//-->
</script>


<a href="java script:dirtypop();">Generate!</a>


But i want in href a embed code inside , when somebody clicks on generate
the pop up will be open with the embed code , and the pop up show it.

Example :<a href="java script:dirtypop(<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/ebu0OBa1pus&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ebu0OBa1pus&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>);">Generate!</a>

jscheuer1
02-19-2008, 10:20 AM
First off:



<a href="java script:al . . .

isn't right. There should be no space, but even so, unless you are unloading the page, you should use an onclick event.

Now your real question is about passing a parameter to the page via the function that contains the HTML of an object/embed tag combo.

You would probably be better off defining each possible (or just the one, if there is only one) such combo as a variable:


var pop_1='<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/ebu0OBa1pus&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ebu0OBa1pus&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';

Then passing that off to the function:


<a href="alternate.htm" onclick="dirtypop(pop_1);return false;">Generate</a>

The alternate.htm could have something on it for non-javascript enabled browsers.

Here's the amended script (you could have a pop_2, a pop_3, and so on, if you like):


<script type="text/javascript">
<!--

var pop_1='<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/ebu0OBa1pus&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ebu0OBa1pus&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';

function dirtypop(content)
{
var generator=window.open('','name','height=500,width= 500,status=1,resizable=0');

generator.document.write('<html><head><title>Popup </title>');
generator.document.write('</head><body>');
generator.document.write('<h1></h1>');
generator.document.write('<p></p>');
generator.document.write('<p>'+content+'</p>');
generator.document.write('<p><a href="javascript:self.close()">Close</a> the popup.</p>');
generator.document.write('</body></html>');
generator.document.close();
}
//-->
</script>

All this may still not avoid the 'click to activate' 'feature' (if that was even a consideration) in IE and Opera though, as that requires an external script, and this may or may not qualify as such to the browser.

Incidentally, what happened when you tried to alert the location of a page that technically has no href? In my experience, you would get:

about:blank

or the href of the generating page.

wais
02-19-2008, 09:23 PM
First off:



isn't right. There should be no space, but even so, unless you are unloading the page, you should use an onclick event.

Now your real question is about passing a parameter to the page via the function that contains the HTML of an object/embed tag combo.

You would probably be better off defining each possible (or just the one, if there is only one) such combo as a variable:


var pop_1='<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/ebu0OBa1pus&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ebu0OBa1pus&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';

Then passing that off to the function:


<a href="alternate.htm" onclick="dirtypop(pop_1);return false;">Generate</a>

The alternate.htm could have something on it for non-javascript enabled browsers.

Here's the amended script (you could have a pop_2, a pop_3, and so on, if you like):


<script type="text/javascript">
<!--

var pop_1='<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/ebu0OBa1pus&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ebu0OBa1pus&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';

function dirtypop(content)
{
var generator=window.open('','name','height=500,width= 500,status=1,resizable=0');

generator.document.write('<html><head><title>Popup </title>');
generator.document.write('</head><body>');
generator.document.write('<h1></h1>');
generator.document.write('<p></p>');
generator.document.write('<p>'+content+'</p>');
generator.document.write('<p><a href="javascript:self.close()">Close</a> the popup.</p>');
generator.document.write('</body></html>');
generator.document.close();
}
//-->
</script>

All this may still not avoid the 'click to activate' 'feature' (if that was even a consideration) in IE and Opera though, as that requires an external script, and this may or may not qualify as such to the browser.

Incidentally, what happened when you tried to alert the location of a page that technically has no href? In my experience, you would get:

about:blank

or the href of the generating page.




Thank you very much saved money.