Embed javascript widget on homepage

Hi guys,

I have the following script generated by Php. The user simply decides which object they want and a script is generated. I only want the user to be able to embed it to their home page using the generated widget. The user is someone like my mother - she doesn’t know Php and the code must work out of the box:

<!-- Embed a flash movie -->
<object data="move.swf" type="application/x-shockwave-flash"></object>

I want to embed it only on the home page using:

var homeUrl = 'http://www.example.com';
if ( document.URL == homeUrl ){
    // true
}else{
    // false    
}

How can I easily execute using javascript / jQuery. I can easily do it with php but as mentioned I want my mother to easily embed widgets without me teaching her php.

You could try using href and origin, problem being it might not always work OK unless you took into account URLs with /index.php, /home.html etc.

if href === origin true

Thank you for the reply. I am able to determine the homepage.

This is the current script, I am not sure if you see what I am trying to do. The script is an auto generator that generates an eme

<?php

	// doing stuff here with php to get height, width and homepage (url - not really desired)
	// output is displayed below

	$fixed_output = '<script type="javascript/text">
            		<object id="theboject" data=http://www.mywebsite.ws/visa-checklist/ width="' . $width . '" height="' . $height . '"> 
						<embed src=http://www.mywebsite.ws/visa-checklist/ width="' . $width . '" height="' . $height . '"> </embed>
						<a href="http://www.mywebsite.ws" target="_blank">WidgetsMafia</a>
					</object>';
?>

<div id="test">
	<!-- This is where I want to echo the script -->
</div>

<script>
	// get home page
	var homeUrl = location.protocol + '//' + location.host;  // this can be the url above

	if ( document.URL == homeUrl ){
		function loadObject() {
			var x = document.getElementById('sourcecde');
    	}

		window.onload = loadObject();
		
	}
	/*
	else{ 
	   //alert("Cannot generate embed code");   
	}
	
</script>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.