iframe on Safari: Failed to load resource

2019-09-06 21:21发布

问题:

I use iframe as below:

<iframe src="http://www.expedia.com/Hotel-Search?#&destination=Abbotsford,%20British%20Columbia,%20Canada&startDate=12/29/2014&endDate=1/3/2015&adults=2" frameborder="0" width="900px" height="900px"></iframe>

It runs well on chrome and firefox, even IE. But on safari, it's fail, I open log and see:

[Error] Failed to load resource: the server responded with a status of 400 (Bad Request) (Hotel-Search, line 0)   http://www.expedia.com/Hotel-Search?inpAjax=true&responsive=true

But when I access that URL directly in new tab, after that comeback to iframe page and refresh page, it runs normal without errors. If I clear history and refresh page, the iframe will be error again. What is the cause? and could you give any solution?

回答1:

In simple terms when you copy and paste the link in the url in another tab and load the expedia page it will start your session with Expedia and set it in your browser... Then since you have started a session with Expedia the iframe will work because you now have a session with Expedia. So if you haven't gone to the site first to get a session the iframe on Safari and IE won't work. The reason they block it is to protect against cross-site scripting attacks which could pose a security risk.