简体   繁体   English

单击链接转到包含嵌入内容的页面时,嵌入不显示

[英]Embed doesnt show up when clicking a link to go to the page with the embedded content

I'm experiencing one of the strangest web bugs I've seen right now and its kind of hard to explain but I'll try my best to.我遇到了我现在见过的最奇怪的网络错误之一,它很难解释,但我会尽力做到这一点。

I'm hosting a small flash games website and I have run into a bug with the way that I'm embedding games.我正在托管一个小型Flash 游戏网站,但我在嵌入游戏的方式上遇到了错误。 Because I really don't feel like writing an HTML file for each game to be embedded on, I created a webpage that when you provide a "URL variable" with the file name of the game, it will create an embed element with the source being the filename.因为我真的不想为每个要嵌入的游戏编写 HTML 文件,所以我创建了一个网页,当您提供带有游戏文件名的“URL 变量”时,它将创建一个带有源的嵌入元素作为文件名。 This works, but only when I directly type in " https://mmgamez.github.io/play.html?game.swf ".这有效,但仅当我直接输入“ https://mmgamez.github.io/play.html?game.swf ”时。 If I click on the link that I put on the "Games" page for a game, it won't pop up (at least for me on ChromeOS).如果我点击我放在游戏“游戏”页面上的链接,它不会弹出(至少对我来说在 ChromeOS 上是这样)。

TLDR/Simplified version: TLDR/简化版:

If I type in https://mmgamez.github.io/play.html?RiddleSchool1.swf in my URL bar the game Riddle School 1 will show up and be playable.如果我在 URL 栏中输入https://mmgamez.github.io/play.html?RiddleSchool1.swf游戏 Riddle School 1 将显示并可以玩。 If I go to the 'Games' tab on my website and click on the link "Riddle School 1" the game will not show up at all.如果我转到我网站上的“游戏”选项卡并单击链接“Riddle School 1”,则游戏根本不会显示。

Heres how I embed my games using a "url variable":下面是我如何使用“url 变量”嵌入我的游戏:


function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}
var game = getUrlVars()["game"];

function embedFile(){
var el = document.getElementById("gamePlace");
var emb = document.createElement("embed");
    emb.setAttribute("width", "800");
    emb.setAttribute("height", "600");
    emb.setAttribute("allowfullscreen", "true");
    emb.setAttribute('src', "games/"+game.toString());
    emb.setAttribute('type', 'application/x-shockwave-flash')
    el.appendChild(emb);
}

Why in the world does this happen and what can I do to fix it?为什么会发生这种情况,我可以做些什么来解决它?

It looks like your getUrlVars() function is working correctly.看起来您的 getUrlVars() 函数工作正常。 However, with query string values, you are looking for key/value pairs (eg key1=value1&key2=value2).然而,对于查询字符串值,您正在寻找键/值对(例如 key1=value1&key2=value2)。

Looking at this line看着这条线

var game = getUrlVars()["game"];

I think you just need to change your links to add "game" as the key:我认为您只需要更改链接以添加“游戏”作为关键:

<a href="https://mmgamez.github.io/play.html?game=RiddleSchool1.swf">RiddleSchool1</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM