user198989
user198989

Reputation: 4663

Append iframe differently?

I appended the iframe as shown below, easily.

$("p").append("<iframe src='http://www.site.com'></iframe>");

But search bots also see this url and go to the url. What I want to do is to make the same append differently. If it was in php, I can do that with

$part1 = "<iframe src='http://www.site";
$part2 = ".com'></iframe>";

echo $part1$part2;

But how can I achieve the same using jquery?

Upvotes: 0

Views: 172

Answers (5)

Arthus
Arthus

Reputation: 116

It shouldn't make any difference how you genereate the iframe because as @felix-kling said it displays the content as HTML in the end and, if the script executes scripts, like it seems to be doing for you if you are already using jQuery to generate the iframe. The next best thing to do is to try and block the script being run.

This can be done in a number of ways,

Put your Script in an external js file in a directory blocked by robots.txt file or even better use a .htaccess file to block external sites from accessing the js files in that directory.

 RewriteEngine On
 RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
 RewriteCond %{HTTP_REFERER} !^$
 RewriteRule .*\.(js)$ - [F]

Upvotes: 4

Thulasiram
Thulasiram

Reputation: 8552

$("p").append($('<iframe />', { 'src' : 'http://www.site.com' })); 

Upvotes: 0

royse41
royse41

Reputation: 2378

Use an array to build up the domain parts:

var domain = [];
domain.push('http://', 'www', 'site', '.com');
$('p').append('<iframe src="', domain.join(''), '"></iframe>');

Upvotes: 1

HGK
HGK

Reputation: 386

Please try the below :

var part1 = "<iframe src='http://www.site"; 
var part2 = ".com'></iframe>"; 
$("p").append(part1+part2);

Upvotes: 1

mowwwalker
mowwwalker

Reputation: 17392

$("p").append("<iframe src='http://www.s"+"ite.com'></iframe>");

Upvotes: 1

Related Questions