...

View Full Version : Alter xhtml in popup



buildrebuild
12-02-2006, 03:34 PM
Hi,
First off, thx j9ine for your help so far and for the following setAttribute code.

http://www.buildrebuild.com/example.zip

This works wonders but what I would ultimatley like to do is put an argumnet in the javascript link like this, so I can use it dynamically across all the links in one page.

<a href="javascript:winInfo.winOpen('test2.htm', 'http://www.bytescout.com/demo/swfscout_SlideShowWithEffects.swf');">test</a>

What this means is that I could change the swf from each link and not have to write out loads of javascript code and have it in separate popup pages...
One popup page which accepts the argument form the xhtml and one xhtml page with alot of links with arguments for the popup.

If anyone can help, pleeeaaase do.
Thx in advance.
CB

j9ine
12-02-2006, 05:25 PM
var winInfo = {

win: null,
flash: null,

winOpen: function(w,f) {
this.flash = f;
this.win = window.open(w,'newWin');
this.win.onload = this.changeParam;
},

changeParam: function() {
//remove existing object
var obj = winInfo.win.document.getElementsByTagName('object')[0];
winInfo.win.document.getElementsByTagName('body')[0].removeChild(obj);

var obj = winInfo.win.document.createElement('object');
obj.setAttribute('classid','clsid:D27CDB6E-AE6D-11cf-96B8-444553540000');
obj.setAttribute('width','200');
obj.setAttribute('height','150');
obj.setAttribute('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab');

var param1 = winInfo.win.document.createElement('param');
param1.setAttribute('name','movie');
param1.setAttribute('value',winInfo.flash);

var param2 = winInfo.win.document.createElement('param');
param2.setAttribute('name','wmode');
param2.setAttribute('value','transparent');

var embed = winInfo.win.document.createElement('embed');
embed.setAttribute('wmode','transparent');
embed.setAttribute('width','200');
embed.setAttribute('height','150');
embed.setAttribute('src',winInfo.flash);
embed.setAttribute('type','application/x-shockwave-flash');
embed.setAttribute('pluginspage','http://www.macromedia.com/go/getflashplayer');

obj.appendChild(param1);
obj.appendChild(param2);
obj.appendChild(embed);
winInfo.win.document.getElementsByTagName('body')[0].appendChild(obj);
}
};

<a href="javascript:winInfo.winOpen('test2.htm', 'http://www.bytescout.com/demo/swfscout_SlideShowWithEffects.swf');">test</a>

buildrebuild
12-02-2006, 09:41 PM
Awesome.
Thx so much. This is too good.

CB

buildrebuild
12-02-2006, 10:24 PM
http://www.buildrebuild.com/linkArgument.htm

Here is a working example. There are a couple of problems. If you click the first link, it changes the original attribute, but on subsequent clicks on that link or the second link, it reverts to the original attribute in the hmtl.

I found that you have to close the popup window and then click on a link to make sure the attribute is set, but is there a way to use the same popup window, or close and reopen the same window?

Thx

j9ine
12-03-2006, 12:22 AM
The code below will check to see if the popup window is open before changing the swf file. If the window is open then it will skip the win.onload command. That command is needed for the first time you open the window to insure that all of the elements are loaded before trying to remove or modify them. If the window is already open then you won't need that command. However, you will need to reset the win property in the winInfo object to null each time the popup is closed. That will force the script to use the onload event the next time the popup is opened. I have not tested this in IE but it is working without errors in FF.


//linkArgument.htm
<html><head>

<script>
var winInfo = {

win: null,
flash: null,

winOpen: function(w,f) {
this.flash = f;
if (!this.win) {
this.win = window.open(w,'newWin','width=500,height=500,toolbar=no,location=no,status=no,scrollbars=no,resizeab le=no');
this.win.onload = this.changeParam;
} else {
this.changeParam();
}
},

changeParam: function() {
var obj = winInfo.win.document.getElementsByTagName('object')[0];
winInfo.win.document.getElementsByTagName('body')[0].removeChild(obj);

var obj = winInfo.win.document.createElement('object');
obj.setAttribute('classid','clsid:D27CDB6E-AE6D-11cf-96B8-444553540000');
obj.setAttribute('width','200');
obj.setAttribute('height','150');
obj.setAttribute('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab');

var param1 = winInfo.win.document.createElement('param');
param1.setAttribute('name','movie');
param1.setAttribute('value',winInfo.flash);

var param2 = winInfo.win.document.createElement('param');
param2.setAttribute('name','wmode');
param2.setAttribute('value','transparent');

var embed = winInfo.win.document.createElement('embed');
embed.setAttribute('wmode','transparent');
embed.setAttribute('width','200');
embed.setAttribute('height','150');
embed.setAttribute('src',winInfo.flash);
embed.setAttribute('type','application/x-shockwave-flash');
embed.setAttribute('pluginspage','http://www.macromedia.com/go/getflashplayer');

obj.appendChild(param1);
obj.appendChild(param2);
obj.appendChild(embed);
winInfo.win.document.getElementsByTagName('body')[0].appendChild(obj);
}
};
/*You can change the attributes eg The location of the swf and the mp3 to be played as below. It will be inserted with rest of object
as 'winInfo.flash'.*/
</script><!-- base href="http://www.buildrebuild.com/linkArgument.htm" --></head><body>

<a href="javascript:winInfo.winOpen('test2.htm', 'http://www.buildrebuild.com/singlemp3player.swf?file=http://www.buildrebuild.com/audio/dirtyDeeds2.mp3');">test</a><br>
<a href="javascript:winInfo.winOpen('test2.htm', 'http://www.buildrebuild.com/singlemp3player.swf?file=http://www.buildrebuild.com/mp3/Cherrybomb.mp3');">test</a>
</body></html>



//test2.htm
<html>
<head>
<script>
window.onunload = resetWin;

function resetWin() {
window.opener.winInfo.win = null;
}
</script>
</head>
<body>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="150" height="20">
<param name="movie" value="http://www.buildrebuild.com/singlemp3player.swf">
<param name="quality" value="high">
<embed src="http://www.buildrebuild.com/singlemp3player.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="150" height="20"></embed>
</object>
</body>
</html>

buildrebuild
12-03-2006, 12:03 PM
Yeah. Works great in ff but in good ol' IE 5.1+ it doesn't.
Will continue to research why it doesn't work in IE.

I am now trying to write out the swf with the flash embed object for IE.

<script type="text/javascript">
var fo = new FlashObject("singlemp3player.swf?file=http://www.buildrebuild.com/audio/dirtyDeeds2.mp3", "animationName", "770", "230", "6", "#fff");
fo.addParam("allowScriptAccess", "sameDomain");
fo.addParam("quality", "high");
fo.addParam("scale", "noscale");
fo.addParam("loop", "false");
fo.write("flashcontent");
</script>

Not sure how to alter the other script as most of the info isn't contained within attributes.

Best
CB

buildrebuild
12-03-2006, 03:54 PM
Also, for the first example, I'm having problems cutting out the popup and just using the code for an iframe in the same page as the link.

Best



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum