gpt4 book ai didi

javascript - 我的报价生成器适用于移动设备,但不适用于桌面设备

转载 作者:行者123 更新时间:2023-11-28 04:39:34 24 4
gpt4 key购买 nike

正如标题所说。我已经完成了 FCC 挑战报价生成器。直到今天早上在所有平台上都运行良好,现在它只在移动设备上运行。不知道是什么原因造成的。任何指针将不胜感激。

Codepen 链接:https://codepen.io/Skitto/pen/dOrXNyHTML

<head>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<script src="https://use.fontawesome.com/225c9ed469.js"></script>
</head>
<body>
<div class="background outerswag">

<div class="box">

<div class="text-center">

<h2 id="quote"> Welcome to the quote generator, enjoy your stay.</h2>
<h4 id="author"></h4>


</div>

<div class = "text-center">
<button id = "quoteGETJSON" class = "btn btn-primary btn-lg outline glyphicon glyphicon-repeat" onclick="this.blur();"></button>
<button id = "tweet" class = "btn btn-primary btn-lg outline fa fa-twitter" onclick="this.blur();"></button>
<h5>created by Skitto</h5>
</div>


</div>
</div>
</div>
</body>

CSS

    html{
background:url("https://source.unsplash.com/category/nature/1920x1080")no-repeat center center fixed;

-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.box{
padding:10%;
color:white;
left: 0;
line-height: 200px;
margin: auto;
margin-top: -100px;
position: absolute;
top: 30%;
width: 100%;

}
.text{
max-width:50%;
}
.btn {
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
font-weight: normal;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
padding: 10px 16px;
}

.btn-lg {
font-size: 18px;
line-height: 1.33;
border-radius: 6px;
}

.btn-primary {
color: white;
background-color: white;
border-color: white;
}

.btn-primary:hover,
.open .dropdown-toggle.btn-primary {
color: #fff;
background-color: grey;
border-color: grey;
}

/***********************
OUTLINE BUTTONS
************************/

.btn.outline {
background: none;
padding: 12px 22px;
}
.btn-primary.outline {
border: 2px solid white;
color: white;
}
.btn-primary.outline:hover, .btn-primary.outline:focus, .open > .dropdown-toggle.btn-primary {
color: black;
border-color: black;
}

/***********************
CUSTON BTN VALUES
************************/

.btn {
padding: 14px 24px;
border: 0 none;
font-weight: 700;
letter-spacing: 1px;
text-transform: uppercase;
}
.btn:focus{
outline: 0 none;
}

Javascript

var authorglobal="";
var quoteglobal="";
$('#quoteGETJSON').click(function() {
$.getJSON("http://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?")
.done(update)
.fail(handleErr);
});


function update(quote) {
$('#quote').html(JSON.stringify(quote.quoteText));
quoteglobal=JSON.stringify(quote.quoteText);
if(quote.quoteAuthor==""){
$('#author').html('-Unknown');
authorglobal="-Uknown";
}else{
var string="-";
string+= JSON.stringify(quote.quoteAuthor);
var returnable=string.replace(/"/g,"");
authorglobal=returnable;
$('#author').html(returnable);
}
//$('html').css('background', 'url(hre)');
}

function handleErr(jqxhr, textStatus, err) {
console.log("Request Failed: " + textStatus + ", " + err);
}

$('#tweet').click(function(){
var url="https://twitter.com/intent/tweet?hashtags=quotes&text="+quoteglobal+authorglobal;

window.open(url) ;
});

最佳答案

它不起作用的原因是您的代码笔 url 是 https,但您请求的是 http 资源。有 mixed content error

如果您通过 http 打开 codepen,它将工作:http://codepen.io/Skitto/pen/dOrXNy

您应该对所有资源使用相同的协议(protocol)。您还可以指定 url,如:“//google.com”,它将设置与当前页面使用的协议(protocol)相同的协议(protocol)。对于您的情况,它将是:

$.getJSON("//api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?")

但是在你的 codepen 中设置并通过 https 运行它是行不通的,因为 api.forismatic.com 存在证书错误

祝你黑客愉快!

关于javascript - 我的报价生成器适用于移动设备,但不适用于桌面设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41283422/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com